/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            shopCommunityManageInfo: {
                shopCommunitys: [],
                total: 0,
                records: 1,
                moreCondition: false,
                scId: '',
                states: [],
                conditions: {
                    state: '',
                    communityId: '',
                    communityName: '',
                    shopId: vc.getCurrentCommunity().shopId
                }
            }
        },
        _initMethod: function () {
            $that._listShopCommunitys(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('s_shop_community', "state", function (_data) {
                $that.shopCommunityManageInfo.states = _data;
            });
        },
        _initEvent: function () {
            vc.on('shopCommunityManage', 'listShopCommunity', function (_param) {
                $that._listShopCommunitys(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listShopCommunitys(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listShopCommunitys: function (_page, _rows) {
                $that.shopCommunityManageInfo.conditions.page = _page;
                $that.shopCommunityManageInfo.conditions.row = _rows;
                var param = {
                    params: $that.shopCommunityManageInfo.conditions
                };
                param.params.communityId = param.params.communityId.trim();
                param.params.communityName = param.params.communityName.trim();
                //发送get请求
                vc.http.apiGet('/shop.queryShopCommunity',
                    param,
                    function (json, res) {
                        var _shopCommunityManageInfo = JSON.parse(json);
                        $that.shopCommunityManageInfo.total = _shopCommunityManageInfo.total;
                        $that.shopCommunityManageInfo.records = _shopCommunityManageInfo.records;
                        $that.shopCommunityManageInfo.shopCommunitys = _shopCommunityManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.shopCommunityManageInfo.records,
                            dataCount: $that.shopCommunityManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddShopCommunityModal: function () {
                vc.emit('addShopCommunity', 'openAddShopCommunityModal', {});
            },
            _openEditShopCommunityModel: function (_shopCommunity) {
                vc.emit('editShopCommunity', 'openEditShopCommunityModal', _shopCommunity);
            },
            _openDeleteShopCommunityModel: function (_shopCommunity) {
                vc.emit('deleteShopCommunity', 'openDeleteShopCommunityModal', _shopCommunity);
            },
            //查询
            _queryShopCommunityMethod: function () {
                $that._listShopCommunitys(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetShopCommunityMethod: function () {
                $that.shopCommunityManageInfo.conditions.state = "";
                $that.shopCommunityManageInfo.conditions.communityId = "";
                $that.shopCommunityManageInfo.conditions.communityName = "";
                $that._listShopCommunitys(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.shopCommunityManageInfo.moreCondition) {
                    $that.shopCommunityManageInfo.moreCondition = false;
                } else {
                    $that.shopCommunityManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
